package com.example.factory.api.controller;

import com.example.factory.api.dto.DtoLevel1Dimension;
import com.example.factory.api.dto.DtoLevel2Dimension;
import com.example.factory.api.dto.Response;
import com.example.factory.api.dto.form.DtoLevel1DimensionForm;
import com.example.factory.api.dto.form.DtoLevel2DimensionForm;
import com.example.factory.api.facade.GradingRuleFacade;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Lei Tao
 */
@RestController
@RequestMapping("/admin/grading/rule")
public class GradingRuleController {
    private final GradingRuleFacade gradingRuleFacade;

    public GradingRuleController(GradingRuleFacade gradingRuleFacade) {
        this.gradingRuleFacade = gradingRuleFacade;
    }

    @GetMapping("/level1/list")
    public Response<List<DtoLevel1Dimension>> selectedLevel1Dimensions() {
        return gradingRuleFacade.selectedLevel1Dimensions();
    }

    @GetMapping("/{level1Guid}/level1")
    public Response<DtoLevel1Dimension> selectedLevel1Dimension(@PathVariable("level1Guid") String level1Guid) {
        return gradingRuleFacade.selectedLevel1Dimension(level1Guid);
    }

    @GetMapping("/{level1Guid}/level1/delete")
    public Response<Void> deletedLevel1(@PathVariable("level1Guid") String level1Guid) {
        return gradingRuleFacade.deletedLevel1(level1Guid);
    }

    @PostMapping("/level1/save")
    public Response<DtoLevel1Dimension> saveOrUpdateLevel1Dimension(@RequestBody DtoLevel1DimensionForm dtoLevel1DimensionForm) {
        return gradingRuleFacade.saveOrUpdateLevel1Dimension(dtoLevel1DimensionForm);
    }

    @GetMapping("/level2/{level1Guid}/list")
    public Response<List<DtoLevel2Dimension>> selectedLevel2Dimensions(@PathVariable("level1Guid")String level1Guid) {
        return gradingRuleFacade.selectedLevel2Dimensions(level1Guid);
    }

    @GetMapping("/{level2Guid}/level2")
    public Response<DtoLevel2Dimension> selectedLevel2Dimension(@PathVariable("level2Guid") String level2Guid) {
        return gradingRuleFacade.selectedLevel2Dimension(level2Guid);
    }

    @GetMapping("/{level2Guid}/level2/delete")
    public Response<Void> deletedLevel2(@PathVariable("level2Guid") String level2Guid) {
        return gradingRuleFacade.deletedLevel2(level2Guid);
    }

    @PostMapping("/level2/save")
    public Response<DtoLevel2Dimension> saveOrUpdateLevel2Dimension(@RequestBody DtoLevel2DimensionForm dtoLevel2DimensionForm) {
        return gradingRuleFacade.saveOrUpdateLevel2Dimension(dtoLevel2DimensionForm);
    }
}
